package com.ziyun.erp.web.modules.business.controller;

import com.ziyun.erp.common.utils.UserUtils;
import com.ziyun.erp.modules.business.entity.OrderSellerScholarshipEntity;
import com.ziyun.erp.modules.business.service.OrderSellerScholarshipService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 黑名单商户订单奖励金
 *
 * @author jiangli
 * @email 
 * @date 2018-12-19 11:02:22
 */
@RestController
@RequestMapping("business/ordersellerscholarship")
public class OrderSellerScholarshipController {
    @Autowired
    private OrderSellerScholarshipService orderSellerScholarshipService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:ordersellerscholarship:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderSellerScholarshipService.list(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("business:ordersellerscholarship:info")
    public R info(@PathVariable("id") Integer id){
        OrderSellerScholarshipEntity orderSellerScholarship = orderSellerScholarshipService.findOne(id);

        return R.ok().put("orderSellerScholarship", orderSellerScholarship);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:ordersellerscholarship:save")
    public R save(@RequestBody OrderSellerScholarshipEntity orderSellerScholarship){
        orderSellerScholarship.setCreateName(UserUtils.getCurentUser().getUsername());
        orderSellerScholarshipService.insert(orderSellerScholarship);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:ordersellerscholarship:update")
    public R update(@RequestBody OrderSellerScholarshipEntity orderSellerScholarship){
        ValidatorUtils.validateEntity(orderSellerScholarship);
        orderSellerScholarship.setUpdateName(UserUtils.getCurentUser().getUsername());
        orderSellerScholarshipService.updateAllColumnById(orderSellerScholarship);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:ordersellerscholarship:delete")
    public R delete(@RequestBody Integer[] ids){
        orderSellerScholarshipService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

    //查询商户ID和商户名称
    @GetMapping("sellerList")
    public R sellerList() {
        List<Map<String, Object>> sellerList = orderSellerScholarshipService.sellerList();
        return R.ok().put("sellerList",sellerList);
    }
}
